package com.ppch.wuwamanus.model.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ppch.wuwamanus.model.entity.User;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * 用户信息实体类（脱敏后的）
 */
@Data
public class UserVO implements Serializable {

    private static final long serialVersionUID = -159956444537961797L;

    /**
     * id
     */
    private Long id;

    /**
     * 账号
     */
    private String userAccount;

    /**
     * 用户昵称
     */
    private String userName;

    /**
     * 用户头像
     */
    private String userAvatar;

    /**
     * 用户角色：user/admin
     */
    private String userRole;

    /**
     * 创建时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    private Date createTime;

    /**
     * 将 UserVO 对象转换为 User 对象
     * @param userVO UserVO
     * @return User
     */
    public static User voToObj(UserVO userVO){
        if(userVO == null){
            return null;
        }
        User user = new User();
        BeanUtils.copyProperties(userVO,user);
        return user;
    }

    /**
     * 将 User 对象转换为 UserVO 对象
     * @param user User
     * @return UserVO
     */
    public static UserVO objToVO(User user){
        if(user == null){
            return null;
        }
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user,userVO);
        return userVO;
    }
}